package com.tyjc.unique.view;

import android.content.Context;
import android.util.AttributeSet;

import java.util.ArrayList;
import java.util.List;

/**
 * 双向滑动父控件（继承自LinearLayout）
 * @author fanxs11
 *
 */
public class MoveScrollAbstract extends AbstractCustomScrollView {
	
	private List<MoveScrollAbstract> scrs = new ArrayList<MoveScrollAbstract>();
	
//	/**
//	 * 关联左侧滑动区域
//	 */
//	private MoveScroll scrLeft;
//	/**
//	 * 关联顶部滑动区域
//	 */
//	private MoveScroll scrTop;
//	/**
//	 * 关联底部滑动区域
//	 */
//	private MoveScroll scrBottom;
	private int type;
	public static final int SCR_CENTER = 0;
	public static final int SCR_LEFT = 1;
	public static final int SCR_TOP = 2;
	public static final int SCR_BOTTOM = 3;

	public MoveScrollAbstract(Context context) {
		super(context);
	}
	
	public MoveScrollAbstract(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

	@Override
	protected void onTouchEventMove(int deltaX, int deltaY) {
		if (scrs == null || scrs.size() < 0) {
			return;
		}
		for (MoveScrollAbstract moveScroll : scrs) {
			if (moveScroll == null) {
				return;
			}
			switch (moveScroll.getType()) {
			case SCR_CENTER:
				moveScroll.scrollBy(deltaX, deltaY);
				break;
			case SCR_LEFT:
				moveScroll.scrollBy(0, deltaY);
				break;
			case SCR_TOP:
				moveScroll.scrollBy(deltaX, 0);
				break;
			case SCR_BOTTOM:
				moveScroll.scrollBy(deltaX, 0);
				break;
			default:
				break;
			}
		}
	}

	@Override
	protected void computeScroll_(int deltaX, int deltaY) {
		if (scrs == null || scrs.size() < 0) {
			return;
		}
		for (MoveScrollAbstract moveScroll : scrs) {
			if (moveScroll == null) {
				return;
			}
			switch (moveScroll.getType()) {
			case SCR_CENTER:
				moveScroll.scrollTo(deltaX, deltaY);
				break;
			case SCR_LEFT:
				moveScroll.scrollTo(0, deltaY);
				break;
			case SCR_TOP:
				moveScroll.scrollTo(deltaX, 0);
				break;
			case SCR_BOTTOM:
				moveScroll.scrollTo(deltaX, 0);
				break;
			default:
				break;
			}
		}
	}
	
	
	public void setGuanLian(List<MoveScrollAbstract> scrs){
		this.scrs.addAll(scrs);
	}
	
//	public MoveScroll getScrLeft() {
//		return scrLeft;
//	}
//
//	public void setScrLeft(MoveScroll scr_left) {
//		this.scrLeft = scr_left;
//	}
//
//	public MoveScroll getScrTop() {
//		return scrTop;
//	}
//
//	public void setScrTop(MoveScroll scr_top) {
//		this.scrTop = scr_top;
//	}
//
//	public MoveScroll getScrBottom() {
//		return scrBottom;
//	}
//
//	public void setScrBottom(MoveScroll scr_Bottom) {
//		this.scrBottom = scr_Bottom;
//	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}


}
